package com.baidu.controller;

import com.baidu.model.entity.CommentModel;
import com.baidu.service.impl.CommentControllerImpl;
import com.until.pagination.PaginationRequest;
import com.until.response.RestfulCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author user
 */
@RestController
@RequestMapping("comment")
public class CommentController {
    @Autowired
    private CommentControllerImpl commentControllerImpl;

    @PostMapping("")
    public RestfulCode.CodeSatCode createComment(@RequestBody CommentModel commentModel){
        commentModel.setCreateTime(new Date());
        return commentControllerImpl.createComment(commentModel);
    }

    @GetMapping("{commentId}/photo/{id}")
    public RestfulCode.CodeSatCode selectByPhotoId(@PathVariable Integer id, @ModelAttribute PaginationRequest page, @PathVariable Integer commentId){
        return commentControllerImpl.selectByPhotoId(id,page,commentId);
    }

    @DeleteMapping("{id}")
    public RestfulCode.CodeSatCode deleteByPhotoId(@PathVariable Integer id){
        return commentControllerImpl.deleteByPhotoId(id);
    }
}
